import { fileURLToPath, URL } from 'node:url';

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueDevTools from 'vite-plugin-vue-devtools';

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue(), vueDevTools()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    proxy: {
      '/igs': {
        target: 'http://localhost:6163', // 保持服务端原始路径
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path, 
        configure: (proxy) => {
          proxy.on('proxyRes', (proxyRes) => {
            // 添加CORS响应头
            proxyRes.headers['Access-Control-Allow-Origin'] = '*';
            proxyRes.headers['Access-Control-Allow-Methods'] =
              'GET, POST, PUT, DELETE, PATCH';
            proxyRes.headers['Access-Control-Allow-Headers'] =
              'X-Requested-With, Content-Type';
          });
        },
      },
    },
  },
});
